package main

import (
	"fmt"
	"html"
	"log"
	"net/http"
	"time"
)

func main() {
	//1,处理http请求
	http.Handle("/ai", http.HandlerFunc(myHandler))
	http.HandleFunc("/bar", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, "hellow , %q", html.EscapeString(r.URL.Path))

	})
	log.Fatal(http.ListenAndServe(":8080", nil))
	//如果想更多的控制服务端行为，可以自定义http。server
	s := &http.Server{
		Addr:           ":8080",
		Handler:        http.HandlerFunc(myHandler),
		ReadTimeout:    10 * time.Second,
		WriteTimeout:   10 * time.Second,
		MaxHeaderBytes: 1 << 20}
	log.Fatal(s.ListenAndServe())

	//2，处理https请求
	//certFile对应ssl证书存放路径 可以，对应证书私钥文件路径
	log.Fatal(http.ListenAndServeTLS(":10443", "cert.pem", "key.pem", nil))
}

func myHandler(w http.ResponseWriter, req *http.Request) {
	fmt.Fprintf(w, "爱你哟")

}
